package com.sync.data.mce.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sync.data.base.BaseEntity;
import com.sync.data.base.CoreField;
import com.sync.data.common.annotation.FieldProps;
import com.sync.data.common.annotation.FieldType;
import com.sync.data.common.annotation.RenderType;
import com.sync.data.common.obj.annoation.ObjectPrefix;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单表实体类
 */
@Getter
@Setter
@Entity
public class OrdMain extends BaseEntity {

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @FieldProps(type = FieldType.DATE, label = "订单提交日期", renderType = RenderType.DatePicker)
    private Date commitTime;

    @FieldProps(type = FieldType.STRING, label = "单据编码")
    private String code;

    @FieldProps(type = FieldType.STRING, label = "下单人PS编码")
    private String empCode;

    @FieldProps(type = FieldType.STRING, label = "下单人")
    private String empName;

    @FieldProps(type = FieldType.STRING, label = "下单人岗位编码")
    private String empPositionCode;

    @FieldProps(type = FieldType.STRING, label = "下单人岗位")
    private String empPositionName;

    @FieldProps(type = FieldType.STRING, label = "业务员", sourceObject = "ViewUserBasicInfo", renderField = "sysUser", renderType = RenderType.SourcePicker)
    private String owner;

    @FieldProps(type = FieldType.STRING, label = "业务员PS编码", reference = "sysUser.workNo",readOnly = true)
    private String bpEmpCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "业务员姓名",reference = "sysUser.realname",readOnly = true)
    private String bpName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "业务员岗位",reference = "sysUser.positionId",readOnly = true)
    private String bpPositionId;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "业务员岗位编码",reference = "sysUser.positionCode",readOnly = true)
    private String bpPositionCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "业务员岗位",reference = "sysUser.positionName",readOnly = true)
    private String bpPositionName;

    @FieldProps(type = FieldType.STRING, label = "业务员销售组织编码",readOnly = true)
    private String bpOrgCode;

    @FieldProps(type = FieldType.STRING, label = "供应商", sourceObject = "MdmIndustrialGroup", renderField = "supplier", renderType = RenderType.SourcePicker)
    private String supId;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "供应商名称", reference = "supplier.name",readOnly = true)
    private String supName;

    @FieldProps(type = FieldType.STRING, label = "公司",reference = "dmsDistAgreement.sellerName")
    private String orgId;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "公司编码", reference = "dmsDistAgreement.mdmIndustrialGroup.businessCode",readOnly = true)
    private String orgCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "公司EAS编码", reference = "dmsDistAgreement.mdmIndustrialGroup.easCode",readOnly = true)
    private String orgEasCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "公司JDE编码", reference = "dmsDistAgreement.mdmIndustrialGroup.jdeCode",readOnly = true)
    private String orgJdeCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "公司名称", reference = "dmsDistAgreement.mdmIndustrialGroup.businessName", readOnly = true)
    private String orgName;

    @FieldProps(type = FieldType.STRING, label = "公司性质", readOnly = true)
    private String orgType;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "公司所属", reference = "dmsDistAgreement.mdmIndustrialGroup.parentGroup", readOnly = true)
    private String orgBelong;

    @FieldProps(type = FieldType.STRING, label = "客户",reference = "dmsDistAgreement.customer")
    private String customerId;

    @FieldProps(type = FieldType.STRING, label = "客户MDM编码", readOnly = true)
    private String mdmCode;

    @FieldProps(type = FieldType.STRING, label = "客户EAS编码",reference = "dmsDistAgreement.viewCustomer.easCode", readOnly = true)
    private String accEasCode;

    @FieldProps(type = FieldType.STRING, label = "客户JDE编码",reference = "dmsDistAgreement.viewCustomer.jdeCode", readOnly = true)
    private String accJdeCode;

    @FieldProps(type = FieldType.STRING, label = "客户统一信用代码", readOnly = true)
    private String accCertificateNumber;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "客户名称", reference = "dmsDistAgreement.viewCustomer.name", readOnly = true)
    private String accName;

    @FieldProps(type = FieldType.DICT, label = "是否限销", renderType = RenderType.Radio)
    private String isRestricted;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "是否限销")
    private CoreField isRestrictedDict;

    @FieldProps(type = FieldType.STRING, label = "关联合同/协议", sourceObject = "DmsDistAgreement", renderField = "dmsDistAgreement", renderType = RenderType.SourcePicker)
    private String contractId;

    @FieldProps(type = FieldType.STRING, label = "合同/协议编号", readOnly = true)
    private String contractCode;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "合同/协议类型", reference = "dmsDistAgreement.agreementType", renderType = RenderType.Select, readOnly = true)
    private String contractType;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "合同/协议类型",reference = "dmsDistAgreement.agreementTypeDict",readOnly = true)
    private CoreField contractTypeDict;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "币别", reference = "dmsDistAgreement.currencyName", readOnly = true)
    private String currency;
//
//    @Transient
//    @FieldProps(type = FieldType.STRING, label = "币别",reference = "dmsDistAgreement.currencyDict",readOnly = true)
//    private CoreField currencyDict;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "开票方式", reference = "dmsDistAgreement.invoiceMethod", renderType = RenderType.Select, readOnly = true)
    private String invoiceMethod;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "开票方式",reference = "dmsDistAgreement.invoiceMethodDict",readOnly = true)
    private CoreField invoiceMethodDict;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "开户银行", reference = "dmsDistAgreement.bankName", readOnly = true)
    private String bankName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "银行账户", reference = "dmsDistAgreement.bankAccount", readOnly = true)
    private String bankAccount;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "结算方式", reference = "dmsDistAgreement.settlementMethod", renderType = RenderType.Select, readOnly = true)
    private String settlementMethod;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "结算方式",reference = "dmsDistAgreement.settlementMethodDict",readOnly = true)
    private CoreField settlementMethodDict;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "付款方式", reference = "dmsDistAgreement.paymentMethod", renderType = RenderType.Select, readOnly = true)
    private String paymentMethod;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "付款方式",reference = "dmsDistAgreement.paymentMethodDict",readOnly = true)
    private CoreField paymentMethodDict;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "账期", reference = "dmsDistAgreement.creditPeriod", renderType = RenderType.Select, readOnly = true)
    private String creditPeriod;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "账期",reference = "dmsDistAgreement.creditPeriodDict",readOnly = true)
    private CoreField creditPeriodDict;

    @Transient
    @FieldProps(type = FieldType.DICT, label = "账期起始节点", reference = "dmsDistAgreement.creditPeriodStartNode", renderType = RenderType.Select, readOnly = true)
    private String creditPeriodStartNode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "账期起始节点",reference = "dmsDistAgreement.creditPeriodStartNodeDict",readOnly = true)
    private CoreField creditPeriodStartNodeDict;

    @FieldProps(type = FieldType.STRING, label = "终端", sourceObject = "ViewCustomer", renderField = "terminal", renderType = RenderType.SourcePicker)
    private String terminalId;

    @FieldProps(type = FieldType.STRING, label = "终端MDM编码", readOnly = true)
    private String terminalCode;

    @FieldProps(type = FieldType.STRING, label = "终端EAS编码", readOnly = true)
    private String terminalEasCode;

    @FieldProps(type = FieldType.STRING, label = "终端JDE编码", readOnly = true)
    private String terminalJdeCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "终端名称", reference = "terminal.name", readOnly = true)
    private String terminalName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "终端统一社会信用代码", reference = "terminal.certificateNumber", readOnly = true)
    private String terminalCertificateNumber;

    @FieldProps(type = FieldType.STRING, label = "收货地址ID", sourceObject = "CrmTransAddressInfo", renderField = "deliverAddress", renderType = RenderType.SourcePicker)
    private String deliverAddressId;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "收货地址名称",reference = "deliverAddress.name", readOnly = true)
    private String deliverAddressName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "收货详细地址",reference = "deliverAddress.address", readOnly = true)
    private String deliverDetailAddress;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "收货联络人",reference = "deliverAddress.contact", readOnly = true)
    private String deliverContactName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "收货联络人手机号码",reference = "deliverAddress.tel",readOnly = true)
    private String deliverContactMobile;

    @FieldProps(type = FieldType.STRING, label = "发运至地址", sourceObject = "CrmTransAddressInfo", renderField = "deliverTo", renderType = RenderType.SourcePicker)
    private String shipToAddressId;

    @FieldProps(type = FieldType.STRING, label = "发运至地址编码", readOnly = true)
    private String shipToAddressCode;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "发运至详细地址",reference = "deliverTo.address", readOnly = true)
    private String shipToAddress;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "发运至联络人",reference = "deliverTo.contact", readOnly = true)
    private String shipToAddressContactName;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "发运至联络人手机号码",reference = "deliverTo.tel",readOnly = true)
    private String shipToAddressContactMobile;

    @FieldProps(type = FieldType.STRING, label = "总未税金额")
    private BigDecimal amount;

    @FieldProps(type = FieldType.STRING, label = "税率")
    private BigDecimal rate;

    @FieldProps(type = FieldType.NUMBER, label = "总数量")
    private Integer totalQuantity;

    @FieldProps(type = FieldType.STRING, label = "含税总价")
    private BigDecimal totalAmount;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @FieldProps(type = FieldType.DATE, label = "期望发货日期", renderType = RenderType.DatePicker)
    private Date expectedDeliveryDate;

    @FieldProps(type = FieldType.STRING, label = "备注",renderType = RenderType.TextArea)
    private String remarks;

    @FieldProps(type = FieldType.DICT, label = "审批状态", renderType = RenderType.Select)
    private String approvalStatus;

    @Transient
    @FieldProps(type = FieldType.STRING, label = "审批状态")
    private CoreField approvalStatusDict;
//    @OneToOne(fetch= FetchType.LAZY)
//    @JoinColumn(name = "orgId", referencedColumnName = "id", insertable = false, updatable = false)
//    @NotFound(action= NotFoundAction.IGNORE)
//    private MdmIndustrialGroup mdmIndustrialGroup;

//    @OneToOne(fetch= FetchType.LAZY)
//    @JoinColumn(name = "customerId", referencedColumnName = "customerId", insertable = false, updatable = false)
//    @NotFound(action= NotFoundAction.IGNORE)
//    private ViewCustomer viewCustomer;

    @OneToOne(fetch= FetchType.LAZY)
    @JoinColumn(name = "contractId", referencedColumnName = "id", insertable = false, updatable = false)
    @NotFound(action= NotFoundAction.IGNORE)
    private DmsDistAgreement dmsDistAgreement;


}

